package view.models;

import java.util.GregorianCalendar;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import domain.Loan;

@SuppressWarnings("serial")
public class OverdueLoansTable extends AbstractTableModel {
	private String[] columnNames = new String[]{"Exemplar",
			"Ausgeliehen an", "Tage"};
	private List<Loan> loans;
	private GregorianCalendar returnDate;
	
	public OverdueLoansTable(List<Loan> loans, GregorianCalendar returnDate){
		this.loans = loans;
		this.returnDate = returnDate;
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return loans.size();
	}

	@Override
	public String getColumnName(int col) {
		return columnNames[col];
	}

	@Override
	public Object getValueAt(int row, int col) {
		Loan l = loans.get(row);
		switch(col){
			case 0:
				return l.getCopy().getInventoryNumber();
			case 1:
				return l.getCustomer().getSurname() + " " + l.getCustomer().getName();
			case 2:
				return l.getDaysOverdue(returnDate);
		}
		return null;
	}
	
	@SuppressWarnings({"unchecked", "rawtypes"})
	public Class getColumnClass(int c) {
		switch(c){
			case 0:
			case 2:
				return Integer.class;
			default:
				return String.class;
		}
	}
}
